package com.atguigu.srb.core.service.impl;

import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.entity.IntegralGrade;
import com.atguigu.srb.core.mapper.IntegralGradeMapper;
import com.atguigu.srb.core.service.IntegralGradeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 积分等级表 服务实现类
 * </p>
 *
 * @author Atguigu
 * @since 2023-05-26
 */
@Service
public class IntegralGradeServiceImpl extends ServiceImpl<IntegralGradeMapper, IntegralGrade> implements IntegralGradeService {

    @Override
    public void queryIntegralGradesByKey(IPage<IntegralGrade> page, Integer key) {
        //mapper的方法查询后 一般返回 行映射的对象 或者 对象集合、或者map    影响的行数
        List<IntegralGrade> list = baseMapper.selectIntegralGradesByKey(page,key);
        //将数据库查询到的分页的记录集合设置到分页对象中
        page.setRecords(list);

    }

    @Override
    public BigDecimal getAmount(String token) {
        Long userId = JwtUtils.getUserId(token);
        return baseMapper.selectAmountByUserId(userId);
    }
}
